package com.fxl.majiang.controller;

import com.fxl.majiang.exception.CustomException;
import com.fxl.majiang.service.MedicalAndPatientInfoService;
import com.fxl.majiang.vo.ApiResponse;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

@RequestMapping("/medicalAndPatientInfo")
@RestController
public class MedicalAndPatientInfoController {

    @Resource
    private MedicalAndPatientInfoService medicalAndPatientInfoService;

    @PostMapping("/upload")
    @ResponseBody
    public ApiResponse<String> upload(@RequestPart("file") MultipartFile file) {
        try {
            medicalAndPatientInfoService.upload(file);
            return ApiResponse.success("");
        } catch (Exception e) {
            e.printStackTrace();
            return ApiResponse.error(e.getMessage());
        }
    }

    @PostMapping("/export")
    public void export(HttpServletResponse response) {
        try {
            medicalAndPatientInfoService.export(response);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
